package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.bean.LiuheBean;
import com.lottery.ruok.lottrey.interfaces.LiuhecaiDetailListWatch;
import com.lottery.ruok.lottrey.retrofitModule.response.GetLotteryDetailResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import ui.NoScrollGridView;

/**
 * Created by ASUS on 2017/11/13.
 */

public class LiuhecaiDetailListView extends BaseAdapter {
    private ArrayList<ArrayList<LiuheBean>> lists;
    private Context mContext;
    private LiuhecaiDetailListWatch liuhecaiDetailListWatch;
    private GetLotteryDetailResponse getLotteryDetailResponse;

    public void setLiuhecaiDetailListWatch(LiuhecaiDetailListWatch liuhecaiDetailListWatch) {
        this.liuhecaiDetailListWatch = liuhecaiDetailListWatch;
    }

    public LiuhecaiDetailListView(ArrayList<ArrayList<LiuheBean>> a, Context context, GetLotteryDetailResponse getLotteryDetailResponse) {//1是特码ab的特码a；2是特码ab的其它
        lists = a;
        mContext = context;
        this.getLotteryDetailResponse = getLotteryDetailResponse;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item3, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        switch (i) {
            case 0:
                holder.name.setText("正一");
                holder.tip.setVisibility(View.VISIBLE);
                break;
            case 1:
                holder.name.setText("正二");
                holder.tip.setVisibility(View.INVISIBLE);
                break;
            case 2:
                holder.name.setText("正三");
                holder.tip.setVisibility(View.INVISIBLE);
                break;
            case 3:
                holder.name.setText("正四");
                holder.tip.setVisibility(View.INVISIBLE);
                break;
            case 4:
                holder.name.setText("正五");
                holder.tip.setVisibility(View.INVISIBLE);
                break;
            default:
                holder.name.setText("正六");
                holder.tip.setVisibility(View.INVISIBLE);
                break;
        }

        NoScrollGridView gridView = view.findViewById(R.id.grid_view);
        gridView.setNumColumns(5);
        final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(lists.get(i), 2, mContext, getLotteryDetailResponse);
        gridView.setAdapter(myAdapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) {
                if(liuhecaiDetailListWatch != null){
                    liuhecaiDetailListWatch.clickWatch(j, i);
                }
            }
        });

        return view;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    static class ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.tip)
        TextView tip;
        @BindView(R.id.grid_view)
        NoScrollGridView gridView;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
